# encoding=utf-8

import time, json, re
import config, instruction
from bot2 import Bot

def prepare(bot):
    bot.send_ins(['{"id":"100003","cmd":"goto xinshou/zhulinrukou"}',
                  '{"id":"100051","cmd":"double_exp ok"}'])
    

def example_task(bot):
    bot.send('{"id":"100051","cmd":"kill dipi3 0"}')
    while True:
        rr = bot.recv_data()
        #{"info":[{"text":"你杀死了地痞头目，得到五天修行，二点潜能。\n战斗结束。","style":{"textColor":"0xFF00FF"}}],"isEnd":1,"back_cmd":"look","id":"100037"}
        try:
            if re.search('你杀死了地痞头目', rr):
                break
            else:
                pass
        except Exception as ex:
            print '解析消息失败: %s' % ex
        print rr

def main():
    username = 'miner004'
    bot = Bot(username, '123456')

    bot.set_register_addr(config.regsi_server)
    bot.set_login_addr(config.login_server)    

    bot.set_prepare(prepare)
    bot.set_task(example_task, 0.5)
    
    bot.start()

main()
